var fs = require('fs');

exports.home = function(req, res) {
	res.render('usermanage/home', {
		title: 'home'
	});
}
exports.article = function(req, res) {
	res.render('usermanage/article', {
		title: 'article'
	});
}
exports.people = function(req, res) {
	res.render('usermanage/people', {
		title: 'people'
	});
}
exports.setting = function(req, res) {
	res.render('usermanage/setting', {
		title: 'setting'
	});
}

exports.edit = function(req, res) {
	res.render('usermanage/edit', {
		title: 'edit'
	});
}
exports.preview = function(req, res){
	res.render('usermanage/preview', {
		title: 'preview'
	});
}
exports.fileupload = function(req, res) {
	// get the temporary location of the file
	var tmp_path = req.files.thumbnail.path;
	// set where the file should actually exists - in this case it is in the "images" directory
	var target_path = './public/' + req.files.thumbnail.name;
	// move the file from the temporary location to the intended location
	fs.rename(tmp_path, target_path, function(err) {
		// delete the temporary file, so that the explicitly set temporary upload dir does not get filled with unwanted files
		// fs.unlink(tmp_path, function() {
		// 	// if(err) throw err;
		// 	res.send('File uploaded to: ' + target_path + ' - ' + req.files.thumbnail.size + ' bytes');
		// });
		res.send(200, JSON.stringify({state:'ok'}));
	});
}